﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TouchedObject : MonoBehaviour {
    public event Action onToched;
    public event Action onExitToch;
    [HideInInspector]
    public bool isTouching = false;
    public GameObject touchedObj
    { get; private set; }
    bool isActive = false;

    public void Active(bool b)
    {
        isActive = b;
    }

    private void OnTriggerEnter(Collider other)
    {
        if (isActive && other.transform.parent.parent.parent.GetComponent<SteamVR_TrackedObject>() != null)
        {
            touchedObj = other.gameObject;
            isTouching = true;
            if (onToched != null)
            {
                onToched();
            }
        }
    }

    private void OnTriggerExit(Collider other)
    {
        if (isActive && other.gameObject == touchedObj)
        {
            isTouching = false;
            touchedObj = null;
            if (onExitToch != null)
            {
                onExitToch();
            }
        }
    }
}
